local function ToggleVMDir ()
	if LocalPlayer():GetActiveWeapon().Classname != "gmod_tool" then return end
	tgm.VMmuldir = -tgm.VMmuldir
end

concommand.Add ("tgm_toggle", ToggleVMDir)

local function ReloadGames ()
	tgm.Games = {}
	tgm:LoadGames()
	tgm:ChangeGame ("game_select")
end

concommand.Add ("tgm_reloadgames", ReloadGames)

local redirectBinds = {
	["+attack"] = true,
	["+attack2"] = true,
	["+moveleft"] = true,
	["+moveright"] = true,
	["+forward"] = true,
	["+back"] = true,
	["+speed"] = true,
	["+duck"] = true,
	["+jump"] = true,
}

local function BindPress (ply, bind, pressed)
	if tgm.VMmul < 1 then return end
	if not ply:Alive() then
		tgm.VMmul = 0
		tgm.VMmuldir = -1
		return
	end
	if bind == "+use" then
		tgm:ChangeGame ("game_select")
	end
	if redirectBinds[bind] then
		if tgm.CurrentGame then
			if pressed then
				tgm.CurrentGame:BindPressed (bind)
			else
				tgm.CurrentGame:BindReleased (bind)
			end
		end
		return true
	end
end

hook.Add ("PlayerBindPress", "tgm.BindPress", BindPress)